package com.cloudsigns.factorymanager2.engineering.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.activity.TeamStatisticalSearchActivity;
import com.cloudsigns.factorymanager2.engineering.customview.AddProductInforPoupWindow;
import com.cloudsigns.factorymanager2.project.customview.GeneralPurposePoupWindow;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;

/**
 * Created by tony on 2018/4/24.
 */

public class TeamStatisticalFragment extends Fragment implements View.OnClickListener ,ItemClickListener {
    private ImageView img_search_types_select,img_search_month_select;
    private EditText edt_search_types,edt_search_month;
    private RelativeLayout rl_search;
    private GeneralPurposePoupWindow generalPurposePoupWindow;
    private String types[] = {"工程统计", "勘察统计","维修统计","上刊统计","巡查统计"};
    private AddProductInforPoupWindow addProductInforPoupWindow;
    private String months[] = {"1月", "2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};

    private String clickType;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_team_statistics, null);
        img_search_types_select=view.findViewById(R.id.img_search_types_select);
        img_search_month_select=view.findViewById(R.id.img_search_month_select);
        edt_search_types=view.findViewById(R.id.edt_search_types);
        edt_search_month=view.findViewById(R.id.edt_search_month);
        rl_search=view.findViewById(R.id.rl_search);

        img_search_types_select.setOnClickListener(this);
        img_search_month_select.setOnClickListener(this);
        rl_search.setOnClickListener(this);
        return view;
    }

    // 查询类型
    private void showSearchTypesWindow(View anchor) {
        generalPurposePoupWindow = new GeneralPurposePoupWindow(getActivity(), types);
        generalPurposePoupWindow.setItemClick(this);
        generalPurposePoupWindow.showPopupWindow(anchor);
    }

    // 查询月份
    private void showSearchMonthsWindow(View anchor){
        addProductInforPoupWindow = new AddProductInforPoupWindow(getActivity(), months);
        addProductInforPoupWindow.setItemClick(this);
        addProductInforPoupWindow.showPopupWindow(anchor);
    }

    @Override
    public void onClick(View view) {
        Intent mIntent;
        switch (view.getId()){
            // 查询类型
            case R.id.img_search_types_select:
                showSearchTypesWindow(edt_search_types);
                clickType="types";
                break;
                // 查询月份
            case R.id.img_search_month_select:
                showSearchMonthsWindow(edt_search_month);
                clickType="month";
                break;
                // 查询
            case R.id.rl_search:
                mIntent=new Intent(getActivity(),TeamStatisticalSearchActivity.class);
                startActivity(mIntent);
                break;
        }
    }

    @Override
    public void itemClick(View view, int position) {
        if ("types".equals(clickType)){
            edt_search_types.setText(types[position]);
        } else if ("month".equals(clickType)){
            edt_search_month.setText(months[position]);
        }
    }
}
